import React, { createContext } from "react";
import useMemoComparative from "../hooks/use-memo-comparative";
import defaultLocale from "../locale/zh-CN";
import { ConfigContextData, ConfigProviderProps } from "./interface";

const DEFAULT_CONFIG: ConfigContextData = {
  locale: defaultLocale,
  safeAreaInsetBottom: false,
  transitionDuration: 300,
};
const a = "叶---第一个-commit";


const b = "叶---第er个-commit";


const c = '叶---第三次提交'


export const Context = createContext<ConfigContextData>(DEFAULT_CONFIG);

const ConfigProvider: React.FC<ConfigProviderProps> = ({
  parentContext,
  children,
  ...restProps
}: ConfigProviderProps) => {
  const cc: ConfigContextData = {
    ...DEFAULT_CONFIG,
    ...parentContext,
    ...restProps,
  };

  const context = useMemoComparative<ConfigContextData, ConfigContextData>(
    () => cc,
    cc,
    (prev: any, next: any) => {
      const prevKeys = Object.keys(prev);
      const nextKeys = Object.keys(next);
      return (
        prevKeys.length !== nextKeys.length ||
        prevKeys.some((key) => prev[key] !== next[key])
      );
    }
  );

  return <Context.Provider value={context}>{children}</Context.Provider>;
};

ConfigProvider.displayName = "ConfigProvider";

export default ConfigProvider;
